﻿using MediatR;
using SuYuanSystem.Applications;
using SuYuanSystem.Domain;
using SuYuanSystem.Repositories;
using SuYuanSystem.WebApi.MedialRs.Commands.Shopps;

namespace SuYuanSystem.WebApi.MedialRs.CommandHandlers.Shopps
{
    public class ShoppCommandHandler : IRequestHandler<ShoppCommand, ApiResult<List<Shopp>>>
    {
        public ShoppCommandHandler(IRepository<Shopp> ShoppRepository)
        {
            this.ShoppRepository = ShoppRepository;
        }

        public IRepository<Shopp> ShoppRepository { get; }

        public Task<ApiResult<List<Shopp>>> Handle(ShoppCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<List<Shopp>> result = new ApiResult<List<Shopp>>();
                result.statusCode = StatusCode.Success;
                result.Message = "查询成功";
                var list = ShoppRepository.GetAll().Result.ToList();
                result.Data = list;
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
